
$(document).on("click", "#upload", function() {
	var file_data = $("#avatar").prop("files")[0]; // Getting the properties of file from file field
	var form_data = new FormData(); // Creating object of FormData class
	form_data.append("file", file_data) // Appending parameter named file with properties of file_field to form_data
	form_data.append("user_id", 123) // Adding extra parameters to form_data
		$.ajax({
		url: url_base+"imatges/uploadImatge",
		dataType: 'script',
		cache: false,
		contentType: false,
		processData: false,
		data: form_data, // Setting the data attribute of ajax with file_data
		type: 'post',
		success: function(data) {
			var data = jQuery.parseJSON(data);
			alert(data);
			$("#output").html(data);
		}
	})
});

function crear_input_formulario(nom_camp){
	nomcamp = nom_camp.replace(/ /g,'');
	$("#nuevo_curso").append('<div id="'+nomcamp+'" class="form-group col-md-12">'+
								'<h4>'+nom_camp+'</h4>'+
					         	'<div class="input-group ">'+
					                ' <div class="input-group-btn input-group-sm">'+
					                      '<button type="button" class="btn btn-warning dropdown-toggle" data-toggle="dropdown">Acció <span class="fa fa-caret-down"></span></button>'+
					                              '<ul class="dropdown-menu">'+
												   	'<li><a href="javascript:eliminar_input(\'#'+nomcamp+'\');">Eliminar</a>'+
												 '</ul>'+
					                ' </div> <!-- /btn-group -->'+
					                 
					           ' <div class="col-md-<?php echo($input_size);?>">'+
					            	' <input type="text" id="'+nom_camp+'"  class="form-control variables">'+
								'</div>'+
					        ' </div>'+
					        ' </div>');
	$('.modal').modal('hide');
}

function select_categoria_curs(idcategoria){
	$("#mod_info_curs").load();
}



$(document).on("click", "#crear_curso", function crear_nuevo_curso() {
	
	var tipus_curs = $("#select_categoria_curs").val();
	var nom_curs = $("#nom_curs").val();
	var text_descripcio = $("#text_descripcio").val();
	
	var variables;
	$(".variables").each(function() {
		var campo = $(this).attr('id');
		var valor = $(this).val();
		if(variables == undefined){
			variables = '"'+campo+'":"'+valor+'"';
		}else{
			variables += ',"'+campo+'":"'+valor+'"';
		}
		
	});

	alert(variables);
	
	$.ajax({
	    url: url_base+"cursos/crearNuevoCurso",
	    data: "tipus_curs="+tipus_curs,
	    type: "POST",			      
		    beforeSend: function() {
		
		}, 
		success: function(data){
				var data = jQuery.parseJSON(data);


	 	}
	});
	
});

/*
function crear_curso(){

		
		
		$.ajax({
            url: url_base+'cursos/crear_nuevo_curso', 
            type: 'POST',
            // Form data
            enctype: 'multipart/form-data',
            data: "nom_curs="+nom_curs+"&image="+image
            //Options to tell jQuery not to process data or worry about content-type.
            //cache: false,
            //contentType: false,
            //processData: false
        });
	
}*/
